package com.test.demo.controller;

import com.test.demo.model.Dictionary;
import com.test.demo.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 编写者：郝嘉
 * 编写时间：2019-05-24
 * 模块功能描述：数据表的增删改查
 */
@RestController(value = "/Dictionary")
public class DictionaryController {
    @Autowired
    private DictionaryService dictionaryService;

    @RequestMapping(value = "/getDic")
    public String getDic(String dic) {
        return "你输入的名字叫：" + dic;
    }

    @CrossOrigin
    @RequestMapping(value = "/getOn")
    public Dictionary getOn(Integer did) {
        return dictionaryService.selectByPrimaryKey2(did);
    }

    @CrossOrigin
    @RequestMapping(value = "/getDid")
    public Dictionary getDid(Integer did) {
        return dictionaryService.selectbyPrimaryKey(did);
    }

    @CrossOrigin    //解决跨域问题
    @RequestMapping(value = "/getDname")
    public List<Dictionary> getDname(){
        System.out.println("调用数据字典全部类型接口");
        List<Dictionary> listDictionary = dictionaryService.getDname();
        return listDictionary;
    }

    @CrossOrigin
    @RequestMapping(value = "/getDis")
    public List<Dictionary> getDis(){
        System.out.println("调用数据字典角色全部信息");
        return dictionaryService.getDis();
    }

    @CrossOrigin
    @RequestMapping(value = "/delDictiory",method = RequestMethod.GET)
    public int delDictionary(Integer did){
        return dictionaryService.delDictionary(did);
    }

    @CrossOrigin
    @RequestMapping(value = "/addDictionary",method = RequestMethod.PUT)
    public int addDictionary(@RequestBody Dictionary dictionarymodel){
        if (dictionarymodel!=null){

        }
        else {

        }
        return dictionaryService.insertDictionary(dictionarymodel);
    }

    @CrossOrigin
    @RequestMapping(value = "/updateDictionary",method = RequestMethod.PUT)
    public int updateDictionary(@RequestBody Dictionary dictionarymodel){
        return dictionaryService.updateDictionary(dictionarymodel);
    }
}
